#include<stdio.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>
#include<string.h>
#include<unistd.h>

int main()
{
    const char* message = "hello world\n";
    write(1, message, strlen(message));

    char buffer[128];
    ssize_t s = read(0, buffer, sizeof(buffer));
    if(s > 0)
    {
        buffer[s - 1] = 0;//因为我们最后还打了一个换行表示结束，buffer把这个也给读进去了，
                          //在不加这句代码时，加上printf语句里面的换行，就会被换行两次
        printf("结果为：%s\n",buffer);
    }

    //int fd1 = open("log1.txt", O_WRONLY | O_CREAT | O_TRUNC, 0666);
    int fd1 = open("log1.txt", O_WRONLY | O_CREAT | O_APPEND, 0666);
    int fd2 = open("log2.txt", O_WRONLY | O_CREAT | O_APPEND, 0666);
    int fd3 = open("log3.txt", O_WRONLY | O_CREAT | O_APPEND, 0666);
    int fd4 = open("log4.txt", O_WRONLY | O_CREAT | O_APPEND, 0666);
    
    printf("fd1: %d\n",fd1);
    printf("fd2: %d\n",fd2);
    printf("fd3: %d\n",fd3);
    printf("fd4: %d\n",fd4);

    write(fd1, message, strlen(message));
    close(fd1);
    return 0;
}


//#define ONE (1<<0)
//#define TWO (1<<1)
//#define THREE (1<<2)
//#define FOUR (1<<3)
//#define FIVE (1<<4)
//
//void PrintTest(int flag)
//{
//    if(flag & ONE)
//        printf("one\n");
//    if(flag & TWO)
//        printf("two\n");
//    if(flag & THREE)
//        printf("three\n");
//    if(flag & FOUR)
//        printf("four\n");
//    if(flag & FIVE)
//        printf("five\n");
//}
//
//int main()
//{
//    PrintTest(ONE);
//    printf("---------------------------------\n");
//    PrintTest(TWO);
//    printf("---------------------------------\n");
//    PrintTest(ONE | TWO);
//    printf("---------------------------------\n");
//    PrintTest(ONE | TWO | THREE);
//    printf("---------------------------------\n");
//    PrintTest(ONE | TWO | THREE | FOUR);
//    printf("---------------------------------\n");
//    return 0;
//}
